package LC;

import java.util.Stack;

public class LC02 {
    public int evalRPN (String[] tokens) {
        // write code here
        Stack<Integer> stack = new Stack<>();
        for(String a:tokens){
            if(!a.equals("*") && !a.equals("-") && !a.equals("+") && !a.equals("/")){
                stack.add(Integer.parseInt(a));
            }else {
                int c =stack.pop();
                int b = stack.pop();
                stack.push(calculate(b,c,a));
            }
        }
        return stack.pop();
    }
    public int calculate(int a,int b,String c){
        switch (c){
            case "+":return a+b;
            case "-":return a-b;
            case "*":return a*b;
            case "/":return a/b;
        }
        return 0;
    }


}